<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    p {
      color: blue;
    }

    #host {
      border: 1px solid green;
    }

    #host::shadow p {
      color: #1e88e5;
    }
  </style>
  <template>
    <p>My host element will have a blue border!</p>
    <style>
      :host {
        border: 1px solid red;
        padding: 10px;
      }
    </style>
  </template>
</head>
<body>
<div id="host" style="border: 1px solid blue;"></div>
<p>I am blue.</p>
<hr>
<script>
  var template = document.querySelector("template")
  var root = document.querySelector("#host").createShadowRoot()

  root.appendChild(template.content)
  setTimeout(function () {
    root.innerHTML += '<style>p { color: green; }</style>'
  }, 2000)
</script>
</body>
</html>